package fule.com.webviewdemo.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import fule.com.webviewdemo.R;

/**
 * 作者： njb
 * 时间： 2018/8/31 0031-下午 5:10
 * 描述：
 * 来源：
 */
public class FM_Know extends Fragment {
    @BindView(R.id.webview)
    WebView webview;
    Unbinder unbinder;
    private View rootView;
    private String content;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.activity_webview, container, false);
        }
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (parent != null) {
            parent.removeView(rootView);
        }
        unbinder = ButterKnife.bind(this, rootView);
        initView();
        return rootView;

    }
    private void initView() {
        content = "<img src=\"https://www.38.hn/images/image/20161104/20161104144203_82117.jpg\" alt=\"\" /><img src=\"https://www.38.hn/images/image/20161116/20161116165842_88829.jpg\" alt=\"\" /><img src=\"https://www.38.hn/images/image/20161104/20161104144206_17003.jpg\" alt=\"\" /><img src=\"https://www.38.hn/images/image/20161104/20161104144207_62404.jpg\" alt=\"\" /><img src=\"https://www.38.hn/images/image/20161104/20161104144208_78881.jpg\" alt=\"\" />";
        String linkCss = "<style type=\"text/css\"> " +
                "img {" +
                "width:100%;" +
                "height:auto;" +
                "}" +
                "</style>";

        String html = "<html><header>" + linkCss + "</header>" + content + "</body></html>";
        webview.loadData(html, "text/html", "UTF-8");
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
